package org.goyo.main.services.sale.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.goyo.common.exception.DBException;
import org.goyo.common.exception.ServiceException;
import org.goyo.main.domain.dao.sale.IDispatchDao;
import org.goyo.main.domain.dao.sale.ISignInDao;
import org.goyo.main.domain.dao.sale.ISaleOrderDao;
import org.goyo.main.domain.entity.sale.SignIn;
import org.goyo.main.services.BaseService;
import org.goyo.main.services.sale.ISignInService;
import org.springframework.stereotype.Service;

@Service
@Transactional
public class SignInServiceImpl  extends BaseService  implements  ISignInService{
	@Resource
	private ISignInDao signInDao;
	@Resource
	private ISaleOrderDao saleOrderDao;
	@Resource
	private IDispatchDao dispatchDao;

	@Override
	public BigDecimal saveOrUpdateInfo(List<SignIn> gridList)	throws DBException, ServiceException {
		BigDecimal amount = new BigDecimal(0);
		for(SignIn signIn : gridList){
			String uuid = signIn.getUuid();
			if(uuid == null || "".equals(uuid)){
				signIn.setUuid(null);
				uuid = signInDao.save(signIn);
			}else{
				signInDao.update(signIn);
			}
			dispatchDao.updateByUuidSignIn(signIn.getResourceEntryId(), signIn.getSignInQty());
		}
		return amount;
	}

	@Override
	public List<SignIn> findByResourceId(String resourceId) throws DBException,
			ServiceException {
		return signInDao.findByResourceId(resourceId);
	}

}
